using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace WIT.Global.JsonConverterHelper;

/// <summary>
/// 将DateTime序列化为字符串yyyy-MM-dd
/// </summary>
public class DateConverter : DateTimeConverterBase
{
	private static IsoDateTimeConverter dtConverter = new IsoDateTimeConverter
	{
		DateTimeFormat = "yyyy-MM-dd"
	};

	/// <summary>
	///
	/// </summary>
	/// <param name="reader"></param>
	/// <param name="objectType"></param>
	/// <param name="existingValue"></param>
	/// <param name="serializer"></param>
	/// <returns></returns>
	public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
	{
		return dtConverter.ReadJson(reader, objectType, existingValue, serializer);
	}

	/// <summary>
	///
	/// </summary>
	/// <param name="writer"></param>
	/// <param name="value"></param>
	/// <param name="serializer"></param>
	public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
	{
		dtConverter.WriteJson(writer, value, serializer);
	}
}
